#ifndef __BE_INTERPOLATOR__
#define __BE_INTERPOLATOR__

class Interpolator
{
 protected:
  UINT64 startTime, endTime, dt;
  bool loop;

  Interpolator();

 public:
  void setStartEndTime(const UINT64 &_start, const UINT64 &_end);
  void setLoop(const bool &_loop);
  void update(const UINT64 &_time);
  virtual void internalUpdate(const UINT64 &_time) = 0;
  virtual ~Interpolator();
};

template<class _C>
class LinearInterpolator : public Interpolator
{
 private:
  _C dValue, startValue, endValue, currValue;

 public:
  LinearInterpolator() {};
  ~LinearInterpolator() {};
  void internalUpdate(const UINT64 &_time)
  {
    if (startTime == _time || _time <= startTime)
      {
	currValue = startValue;
	return;
      }

    if ( !loop && _time >= endTime )
      {
	currValue = endValue;
	return;
      }

    for(int i = 0; i < _C::SIZE; ++i)
      {
	currValue[i] = startValue[i] + (dValue[i] * ((float)(( _time - startTime ) % dt) / dt ));
      }
  }
 
  void setStartEndValue(const _C &_start, const _C &_end)
  {
    startValue = _start;
    endValue   = _end;

    for(int i=0; i < _C::SIZE; ++i)
      {
	dValue[i] = endValue[i] - startValue[i];
      }
  }

  const _C& getValue()
  {
    return currValue;
  }
};

#endif
